package com.zb.web.servlet;

import com.alibaba.fastjson.JSON;
import com.zb.Service.UserService;
import com.zb.Service.impl.UserServiceImpl;
import com.zb.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/registerUserServlet")
public class RegisterUserServlet extends HttpServlet {
    private UserService userService=new UserServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader br = request.getReader();
        String params = br.readLine();

        User user = JSON.parseObject(params, User.class);

        userService.registerUser(user);
        response.getWriter().write("success");
    }
}
